package com.wyp.demo.boot;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.wyp.demo.R;
import com.wyp.demo.active.ActiveUserActivity;
import com.wyp.demo.netret.WifiConfigActivity;
import com.wyp.demo.utils.ETVConstant;
import com.wyp.demo.version.VersionConfigActivity;

public class BootProcessActivity extends Activity {
	Button btn1,btn2,btn3,btn4,btn5;
	TextView tv;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bootprocess);
		initBtn();
		tv = (TextView)findViewById(R.id.textView1);
	}
	
	private void initBtn() {
		btn1 = (Button)findViewById(R.id.button1);
		btn1.setOnClickListener(new MyBtnClick());
		btn2 = (Button)findViewById(R.id.button2);
		btn2.setOnClickListener(new MyBtnClick());
		btn3 = (Button)findViewById(R.id.button3);
		btn3.setOnClickListener(new MyBtnClick());
		btn4 = (Button)findViewById(R.id.button4);
		btn4.setOnClickListener(new MyBtnClick());
		btn5 = (Button)findViewById(R.id.button5);
		btn5.setOnClickListener(new MyBtnClick());
	}
	
	private void checkWifiNet() {
		openWifiConfig();
	}
	private void checkActiveUser() {
		openActiveUser();
	}
	private void checkVersion() {
		openVersionDownload();
	}
	private void openActiveUser() {
		Intent intent=new Intent();
        intent.setClass(BootProcessActivity.this, ActiveUserActivity.class);
        startActivityForResult(intent,0);
	}
	private void openWifiConfig() {
		Intent intent=new Intent();
        intent.setClass(BootProcessActivity.this, WifiConfigActivity.class);
        startActivityForResult(intent,0);
	}
	private void openVersionDownload() {
		Intent intent=new Intent();
        intent.setClass(BootProcessActivity.this, VersionConfigActivity.class);
        startActivityForResult(intent,0);
	}
	private void openEtvMain() {
		Intent intent=new Intent();
		intent.setComponent(new ComponentName("com.cn.newetv","com.cn.newetv.ETVHome"));
		intent.setAction(Intent.ACTION_VIEW);
        startActivityForResult(intent,0);
	}
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
		try {
			switch (resultCode) {
			case ETVConstant.BOOT_CHECK_WIFI_NET_SUCCEED:

				break;
			case ETVConstant.BOOT_CHECK_WIFI_NET_FAILED:

				break;
			case ETVConstant.BOOT_CHECK_ACTIVE_USER_SUCCEED:

				break;
			case ETVConstant.BOOT_CHECK_ACTIVE_USER_FAILED:

				break;
			case ETVConstant.BOOT_CHECK_VERSION_SUCCEED:

				break;
			case ETVConstant.BOOT_CHECK_VERSION_FAILED:

				break;
			default:
				break;
			}
			if (data == null)
				return;
			Bundle b = data.getExtras();
			String txt = b.getString("msg");
			tv.setText(txt);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class MyBtnClick implements OnClickListener {
		public void onClick(View v) {
			try {
				if(v.equals(btn1)) {
					checkWifiNet();
				} else if(v.equals(btn2)) {
					checkActiveUser();
				} else if(v.equals(btn3)) {
					checkVersion();
				} else if(v.equals(btn4)) {
					openEtvMain();
				} else if(v.equals(btn5)) {
					testSlientInstall();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void testSlientInstall() {
		try {
			String sdpath = Environment.getExternalStorageDirectory() + "/";
			String installpath = sdpath+"etv/etv.apk";


		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
